package login

import java.net.URL
import java.util.ResourceBundle

import application.mac.Mac
import javafx.fxml.{FXML, Initializable}
import javafx.scene.control._
import javafx.stage.Stage
import org.joda.time.DateTime
import tool.Tool
import utils.Implicits._
import utils.Utils


class LoginEvent extends Initializable {

  @FXML var macAddressTextField: TextField = _
  @FXML var seriesTextArea: TextArea = _

  override def initialize(location: URL, resources: ResourceBundle) = {

    macAddressTextField.setText(Utils.getMac)
    val now = new DateTime()
    val totalDay = 90

  }

  @FXML def confirm = {
    val series = seriesTextArea.getText
    val macAddress = Utils.getMac
    val stage = seriesTextArea.getScene.getWindow.asInstanceOf[Stage]
    val encStr = DesEncrypter.encrypt(macAddress)
    if (series != encStr) {
      Utils.showError("错误！", "请输入合法的序列号！", stage)
    } else {
      series.toFile(Tool.licenceFile)
      Tool.enterMain(stage)
    }
  }


}
